package org.wangnian.validationdemo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.wangnian.validationdemo.groups.user.InsertUser;
import org.wangnian.validationdemo.model.UserDetails;
import org.wangnian.validationdemo.model.UserRequest;
import org.wangnian.validationdemo.service.UserService;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/add")
    public String add(@Validated(value = {InsertUser.class}) UserRequest userRequest){
        return "添加成功";
    }

    @PostMapping("/add1")
    public String add1(String username,String password){
        userService.add(username,password);
        return "添加成功";
    }

    @PostMapping("/add2")
    public String add2(@RequestBody(required = false) UserDetails userDetails){
        userService.add(userDetails);
        return "添加成功";
    }


}
